from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#弹窗的两种定位判断方法
#1，一种结果定位
# try:
#     # 显式等待弹窗出现，最长1秒，每0.2秒检查一次
#     WebDriverWait(self.driver, 1, 0.2).until(
#         EC.presence_of_element_located((By.XPATH, '//*[contains(text(),"删除该银行卡成功")]'))
#     )
#     # 如果等待成功，说明弹窗出现过，返回True
#     return True
# except:
#     # 若超时未找到，说明弹窗未出现，返回False
#     return False
#2，多种结果定位
# def get_login_NO_result(self,result):
#     if result == '账号或密码不正确':
#         try:
#              WebDriverWait(self.driver, 1, 0.2).until(
#                 EC.presence_of_element_located((By.XPATH, '//*[contains(text(),"账号或密码不正确")]')))
#              return True
#         except:
#              return False
#     elif result == '欢迎使用 银行贷款管理系统':
#         try:
#             WebDriverWait(self.driver, 1, 0.2).until(
#                 EC.presence_of_element_located((By.XPATH, '//*[contains(text(),"欢迎使用 银行贷款管理系统")]')))
#             return True
#         except:
#             return False
#     else:
#         try:
#             WebDriverWait(self.driver, 1, 0.2).until(
#                 EC.presence_of_element_located((By.XPATH, '//*[contains(text(),"请输入用户名")]')))
#             return True
#         except:
#             return False
###################################################################################################################
#判断查询结果是否符合
# rows = self.driver.find_elements(By.XPATH, '//table[@class="el-table__body"]/tbody/tr')
# user1 = str(user1).strip() if user1 is not None else None
# name1 = str(name1).strip() if name1 is not None else None
# if not rows and result == '无结果':
#     return True
# # 情况：预期应该有结果却没查到
# if not rows and result != '无结果':
#     return False
# all_match = True  # 所有行是否都匹配条件
# for row in rows:
#     cols = row.find_elements(By.TAG_NAME, 'td')
#     account = cols[2].text.strip()
#     bank = cols[3].text.strip()
#     if user1 and not name1:  # 只查账号
#         if user1 not in account:
#             all_match = False
#             break
#     elif name1 and not user1:  # 只查银行名
#         if name1 not in bank:
#             all_match = False
#             break
#     elif user1 and name1:  # 查账号和银行名
#         if user1 not in account or name1 not in bank:
#             all_match = False
#             break
#     elif not user1 and not name1:  # 查全部
#         if len(rows) == 0:
#             all_match = False
#             break
# return all_match